package com.ruoyi.framework.security.jsonlogin;

import com.ruoyi.common.core.domain.model.LoginBody;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

@Setter
@Slf4j
public class JsonLoginAuthenticationToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = -8221018566416863145L;

    private Object principal;

    private Object credentials;

    @Getter
    private LoginBody loginBody;

    public JsonLoginAuthenticationToken(Object principal, Object credentials, LoginBody loginBody) {
        super(null);
        this.principal = principal;
        this.credentials = credentials;
        this.loginBody = loginBody;
        setAuthenticated(false);
    }

    public JsonLoginAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true);
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

    @Override
    public Object getCredentials() {
        return credentials;
    }

}
